package com.chezhujie.www.service;

import com.chezhujie.www.domain.CzjcommentsPic;
import com.chezhujie.www.persistence.CzjcommentsPicMapper;
import com.xy.core.exception.ClassCheckException;
import com.xy.user.base.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 评论图片
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class CzjcommentsPicService extends BaseService<CzjcommentsPic> {
    @Autowired
    private CzjcommentsPicMapper czjcommentspicMapper;

    @Autowired
    public void setBaseMapper(CzjcommentsPicMapper czjcommentspicMapper) {
        this.baseMapper = czjcommentspicMapper;
    }

    public List<Map<String,Object>> getListCommentsId(Map<String, Object> param) {
        return czjcommentspicMapper.listCommentsId(param);
    }

    public void checkEntity(CzjcommentsPic czjcommentspic) throws ClassCheckException {
        if(czjcommentspic.getPicPath()!=null&&czjcommentspic.getPicPath().length()>255){
            throw new ClassCheckException("评论图片评论图片不能超过255个字符");
        }
    }
    public void checkListEntity(List<CzjcommentsPic> listCzjcommentsPic) throws ClassCheckException {

        for (CzjcommentsPic czjcommentspic : listCzjcommentsPic) {
            checkEntity(czjcommentspic);
        }

    }

    @Override
    public void insert(CzjcommentsPic czjcommentsPic) {
        czjcommentsPic.setApproveStatus(0);
        czjcommentsPic.setCreateTime(new Date());
        czjcommentsPic.setDelFlag(0);
        super.insert(czjcommentsPic);
    }
    /**
     * 修改审批状态
     * @param id
     * @param approveStatus
     */
    public void changeApprove(String id, Integer approveStatus) {
        CzjcommentsPic entity = queryById(id);
        entity.setApproveStatus(approveStatus);
        entity.setApproveTime(new Date());
        update(entity);
    }
    @Override
    public void saves(List<CzjcommentsPic> list) {
        for (int i = 0; i < list.size(); i++) {
            list.get(i).setApproveStatus(0);
            list.get(i).setCreateTime(new Date());
            list.get(i).setDelFlag(0);
        }
        super.saves(list);
    }

    public List<Map<String,Object>> getByCommentsId(String commentsId) {
        return czjcommentspicMapper.getByCommentsId(commentsId);
    }
}
